<template>
  <body id="poster">
  <el-form class="login-container" label-position="left"
           label-width="0px">
    <h3 class="login_title">村事宝后台管理系统系统登录</h3>
    <el-form-item>
      <el-input type="text" v-model="loginForm.u_id"
                auto-complete="off" placeholder="账号 默认10013"></el-input>
    </el-form-item>
    <el-form-item>
      <el-input type="password" v-model="loginForm.u_password"
                auto-complete="off" placeholder="密码 默认123456"></el-input>
    </el-form-item>
    <el-form-item style="width: 100%">
      <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="login">登录</el-button>
    </el-form-item>
  </el-form>
  </body>
</template>
<style>
#poster {
  background: url("../../../digital_villiage_ui/src/assets/background-01.jpg") no-repeat center;
  height: 100%;
  width: 100%;
  background-size: cover;
  position: fixed;
}
body{
  margin: 0px;
}
.login-container {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 230px auto 90px;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}

.login_title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}

</style>

<script>
export default {
  name: 'Login',
  emulateJSON: true,
  data () {
    return {
      loginForm: {
        u_id: '',
        u_password: ''
      },
      responseResult: []
    }
  },
  methods: {
    login () {
      // 测试阶段服务器绕开登录使用
      // var path = this.$route.query.redirect
      // this.$router.replace({path: path === '/' || path === undefined ? '/' : path})
      //
      // 运营阶段登录页面登录
      const _this = this
      this.$axios
        .post('/userlogin', {
          u_id: _this.loginForm.u_id,
          u_password: _this.loginForm.u_password
        }, {emulateJSON: true})
        .then(successResponse => {
          console.log('ping success')
          console.log(JSON.stringify(successResponse.data))
          if (successResponse.data.u_id !== -1) {
            // console.log('loginForm: ' + JSON.stringify(_this.loginForm))
            _this.$store.commit('login', successResponse.data)
            var path = this.$route.query.redirect
            this.$router.replace({path: path === '/' || path === undefined ? '/' : path})
          }
        })
        .catch(failResponse => {
          this.$message.error('网络错误,请使用谷歌浏览器使用')
          console.log('failed')
        })
    }

  }
}
</script>

<style scoped>

</style>
